import React from 'react';
import {connect} from 'react-redux';
import {Form, Tabs, Spin} from 'antd';
import {messages} from "share/common";
const TabPane = Tabs.TabPane;
import MessagesSetting from "containers/setting/notification-setting/notification-content/messages-setting"
class NotificationSettingContent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: false,
      pageLoading: false,
      status: 'approve-remind',
      tabs: [
        {key: 'approve-remind', name: messages('setting.key1561')/*审批提醒*/,type:2},
        {key: 'press-remind',name:messages('setting.key1697')/*手动催办*/,type:3},
      ],
      defaultMessageForm: [
        {type: 'switch', id: 'valid', label: messages('setting.key1096')/*状态*/, isRequired: false,defaultValue:true},
        {type: 'languageInput', id: 'title', label: messages('setting.key54'/*标题*/), isRequired: true, textArea: false,

          title:messages('setting.key1562')/*单据审批提醒*/,},
        {type: 'languageInput', id: 'content', label:  messages('setting.key744'/*提醒内容*/), isRequired: true, textArea: true,
          contentText:messages('setting.key1578'),/*您有（待审批单据数量）张单据等待审批*/
          content: messages('setting.key1563')/*请尽快处理*/,
        },
        {
          type: 'radio-company',
          id: 'visibleCompanyScope',
          label: messages('setting.key730')/*适用公司*/,
          defaultValue:1,
          isRequired: true,
          options: [{value: 1, label: messages('setting.key219')/*全部*/}, {value: 2, label: messages('setting.key1229')/*部分*/}]
        },
        {type: 'chooser', id: 'ruleId', label: messages('setting.key1566')/*提醒规则*/, isRequired: true},
      ],
    };
  }

  componentWillMount() {
    this.setState({statue: 'approve-remind', messageForm: this.state.defaultMessageForm})
  }

  onChangeTabs = (key) => {
    let defaultMessageForm =[
      {type: 'switch', id: 'valid', label: messages('setting.key1096')/*状态*/, isRequired: false,defaultValue:true},
      {type: 'languageInput', id: 'title', label: messages('setting.key54'/*标题*/), isRequired: true, textArea: false,
        title:messages('setting.key1562')/*单据审批提醒*/,},
      {type: 'languageInput', id: 'content', label:  messages('setting.key744'/*提醒内容*/), isRequired: true, textArea: true,
        contentText:messages('setting.key1578'),/*您有（待审批单据数量）张单据等待审批*/
        content: messages('setting.key1563')/*请尽快处理*/,
      },
      {
        type: 'radio-company',
        id: 'visibleCompanyScope',
        label: messages('setting.key730')/*适用公司*/,
        defaultValue:1,
        isRequired: true,
        options: [{value: 1, label: messages('setting.key219')/*全部*/}, {value: 2, label: messages('setting.key1229')/*部分*/}]
      },
      {type: 'chooser', id: 'ruleId', label: messages('setting.key1566')/*提醒规则*/, isRequired: true},
    ];
    let messageForm =  [
      {type: 'switch', id: 'valid', label: messages('setting.key1096')/*状态*/, isRequired: false,defaultValue:true},
      {type: 'languageInput', id: 'title', label: messages('setting.key54'/*标题*/), isRequired: true, textArea: false,
        // contentArr:[{messages('setting.key485')/*单据类型*/},{messages('setting.key1698')/*单据编号*/}],
        contentArr:[{name:messages('setting.key485')/*单据类型*/,code:'DocTyp'},{name:messages('setting.key1698')/*单据编号*/,code:'DocNo'}],
        title:messages('setting.key1699')/*单据催办提醒*/+'#DocTyp#'+'#DocNo#',
      },
      {type: 'languageInput', id: 'content', label:  messages('setting.key744'/*提醒内容*/), isRequired: true, textArea: true,
        // contentArr:[{messages('setting.key1700')/*催办人*/},{messages('setting.key1701')/*提交人*/},{messages('setting.key485')/*单据类型*/},{messages('setting.key1698')/*单据编号*/}],
        contentArr:[{name:messages('setting.key1700')/*催办人*/,code:'RemPeop'},{name:messages('setting.key1701')/*提交人*/,code:'ReqPeop'},{name:messages('setting.key485')/*单据类型*/,code:'DocTyp'},{name:messages('setting.key1698')/*单据编号*/,code:'DocNo'}],
        content:'#RemPeop#'+messages('setting.key1702')/*提示：请尽快审批*/+'#ReqPeop#'+messages('setting.key500')/*提交的*/+'#DocTyp#'+'#DocNo#'},
      {
        type: 'radio-company',
        id: 'visibleCompanyScope',
        label: messages('setting.key730')/*适用公司*/,
        defaultValue:1,
        isRequired: true,
        options: [{value: 1, label: messages('setting.key219')/*全部*/}, {value: 2, label: messages('setting.key1229')/*部分*/}]
      },
      {type: 'chooser', id: 'ruleId', label: messages('setting.key1566')/*提醒规则*/, isRequired: true},
      ];
    switch (key) {
      case 'approve-remind':
        this.setState({status: key, messageForm: defaultMessageForm})
        break;
      case 'press-remind':
        this.setState({status: key, messageForm: messageForm})
        break;
    }

  };


  render() {
    const {tabs, status, pageLoading, messageForm} = this.state;
    return (
      <div>
        <Tabs type="line" tabPosition="left" activeKey={status} onChange={this.onChangeTabs}>
          {tabs.map(item => {
            return (
              <TabPane tab={item.name} key={item.key}>
                {item.key === status && <Spin spinning={pageLoading}>
                  <MessagesSetting type={item.type} messageForm={messageForm}/>
                </Spin>}
              </TabPane>
            )
          })}
        </Tabs>
      </div>
    )
  }

}

NotificationSettingContent.contextTypes = {
  router: React.PropTypes.object
};

function mapStateToProps(state) {
  return {
    tenantMode: state.main.tenantMode,
  }
}


const wrappedNotificationSettingContent = Form.create()(NotificationSettingContent);

export default connect(mapStateToProps)(wrappedNotificationSettingContent)

